package com.baj.ldap.entry;

import org.springframework.ldap.core.AttributesMapper;

import javax.naming.NamingException;
import javax.naming.directory.Attributes;

public class PersonAttributesMapper implements AttributesMapper<Person> {

    @Override
    public Person mapFromAttributes(Attributes attrs) throws NamingException {
        Person person = new Person();

        if (attrs.get("sn") != null) {
            person.setSn((String) attrs.get("sn").get());
        }
        if (attrs.get("cn") != null) {
            person.setCn((String) attrs.get("cn").get());
        }
        if (attrs.get("distinguishedName") != null) {
            person.setDn((String) attrs.get("distinguishedName").get());
        }
        if (attrs.get("ou") != null) {
            person.setOu((String) attrs.get("ou").get());
        }
        if (attrs.get("userPassword") != null) {
            person.setUserPassword((String) attrs.get("userPassword").get());
        }
        if (attrs.get("telephoneNumber") != null) {
            person.setTelephoneNumber((String) attrs.get("telephoneNumber").get());
        }
        if (attrs.get("name") != null) {
            person.setName((String) attrs.get("name").get());
        }
        if (attrs.get("description") != null) {
            person.setDescription((String) attrs.get("description").get());
        }
        if (attrs.get("givenName") != null) {
            person.setGivenName((String) attrs.get("givenName").get());
        }
        if (attrs.get("userPassword") != null) {
            person.setUserPassword((String) attrs.get("userPassword").get());
        }
        if (attrs.get("telephoneNumber") != null) {
            person.setTelephoneNumber((String) attrs.get("telephoneNumber").get());
        }
        if (attrs.get("mobile") != null) {
            person.setMobile((String) attrs.get("mobile").get());
        }
        if (attrs.get("displayName") != null) {
            person.setDisplayName((String) attrs.get("displayName").get());
        }
        if (attrs.get("company") != null) {
            person.setCompany((String) attrs.get("company").get());
        }
        if (attrs.get("department") != null) {
            person.setDepartment((String) attrs.get("department").get());
        }
        if (attrs.get("title") != null) {
            person.setTitle((String) attrs.get("title").get());
        }
        if (attrs.get("lastLogonTimestamp") != null) {
            person.setLastLogonTimestamp((String) attrs.get("lastLogonTimestamp").get());
        }
        if (attrs.get("whenCreated") != null) {
            person.setCreateTime((String) attrs.get("whenCreated").get());
        }
        if (attrs.get("whenChanged") != null) {
            person.setModifyTime((String) attrs.get("whenChanged").get());
        }
        if (attrs.get("isDeleted") != null) {
            person.setIsDelete((Boolean) attrs.get("isDeleted").get());
        }
        if (attrs.get("mail") != null) {
            person.setMail((String) attrs.get("mail").get());
        }
        if (attrs.get("mailNickName") != null) {
            person.setMailNickName((String) attrs.get("mailNickName").get());
        }
        if (attrs.get("physicalDeliveryOfficeName") != null) {
            person.setPhysicalDeliveryOfficeName((String) attrs.get("physicalDeliveryOfficeName").get());
        }
        if (attrs.get("sAMAccountName") != null) {
            person.setSAMAccountName((String) attrs.get("sAMAccountName").get());
        }
        if (attrs.get("userPrincipalName") != null) {
            person.setUserPrincipalName((String) attrs.get("userPrincipalName").get());
        }

        return person;
    }
}
